<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>v-for</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<h1>v-for作用：循环遍历数组</h1>
<div id="app">
    <button @click="add">添加</button>
    <button @click="del">删除</button>
    <ul>
        <li v-for="item in list">{{item}}</li>
    </ul>
    <table border="1px" cellspacing="0" width="100%">
        <tr>
            <th>idx</th>
            <th>name</th>
            <th>age</th>
        </tr>
        <tr align="center" v-for="(item,index) in list">
            <td>{{index + 1}}</td>
            <td>{{item.name}}</td>
            <td>{{item.age}}</td>
        </tr>
    </table>
</div>
<script>
    new Vue({
        el: '#app',
        data: {
            list: [
                {name: '张三', age: 18},
                {name: '李四', age: 19},
                {name: '王五', age: 20}
            ]
        },
        methods: {
            add() {
                this.list.push({name: '赵六', age: 21})
            },
            del() {
                this.list.pop()
            }
        }
    })
</script>
</body>
</html>